package cz.myslivec.knihovna.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import cz.myslivec.knihovna.entity.Category;

@Name("categoryDaoImpl")
@AutoCreate
public class CategoryDaoImpl implements CategoryDao {

	@In
	private EntityManager entityManager;

	public void create(Category category) {
		entityManager.persist(category);
	}

	public void delete(Category category) {
		entityManager.remove(category);
	}

	public void update(Category category) {
		entityManager.merge(category);
	}

	public Category getCategory(String code) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<Category> list() {
		Query query = entityManager.createQuery("from Category");
		return (List<Category>)query.getResultList();
	}

}
